package com.link.notify;

import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

import javax.annotation.Resource;

/**
 * 邮件通知实现类
 * @author 郭闪
 * @date 2019/12/23
 */
public class LinkEmailNotify {

    /**
     * 发送邮件主题
     */
    private String mailSubject;
    /**
     * 邮件接收者
     */
    private String[] receivers;
    /**
     * 邮件发送人
     */
    private String from;

    public String getMailSubject() {
        return mailSubject;
    }

    public void setMailSubject(String mailSubject) {
        this.mailSubject = mailSubject;
    }

    public String[] getReceivers() {
        return receivers;
    }

    public void setReceivers(String[] receivers) {
        this.receivers = receivers;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    /**
     * 注入spring boot email 中的邮件发送bean
     */
    @Resource
    private JavaMailSenderImpl mailSender;



    /**
     * 发送邮件通知
     * @author 郭闪
     * @date 2019/12/25
     * @param notifyContent  邮件内容，此处仅支持纯文本格式的内容
     *
     */
    public void notify(String notifyContent) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(this.from);
        message.setTo(this.receivers);
        message.setSubject(this.mailSubject);
        message.setText(notifyContent);
        mailSender.send(message);
    }
}
